<template>
  <div class="content">
    
    <div class="accountCon">
      <div class="btnBox">
        <div v-if="clienId"></div>
        
        <el-button
          type="primary"
          v-if="clienId"
          class="mb10"
          size="mini"
          round
          @click="visitClient = true"
        >添加修复</el-button>
      </div>
      
      <div class="entryBox" v-if="clienId">
        <el-empty v-if="notHave" description="暂无数据" class="mr50 mt50"></el-empty>
        <div v-for="item in list" :key="item.id">
          <div class="entryRow1">
            <div class="item-circle mr30" />
            <div class="clientName">{{item.customer_name}}</div>
            <div class="entryRow2">
              <div class="ml20">{{item.repair_visitor_name}}</div>
              <div class="ml20">{{item.repair_plan_time}}</div>
            </div>
          </div>
          <div class="entryRow3">
            <div>{{item.repair_plan_content}}</div>
          </div>
        </div>
      </div>
    </div>

    <el-dialog title="添加修复方案" :visible.sync="visitClient" :close-on-click-modal="false">
      <el-form
        ref="detail"
        label-position="right"
        label-width="200px"
        :rules="rules"
        :model="detail"
        class="frame"
      >
        <el-form-item label="客户姓名:">
          <el-input v-model="consignee" class="w300" readonly></el-input>
        </el-form-item>
        <el-form-item label="方案内容" prop="repair_plan_content">
          <el-input
            v-model="detail.repair_plan_content"
            class="w300"
            placeholder="请填写修复方案"
            type="textarea"
          />
        </el-form-item>

        <div class="footerBtn">
          <el-button type="primary" size="mini" class="mainBtn" @click="submitForm('detail')">完成，提交</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import pagination from "@/components/Pagination";
import {
  addPlanList,
  repairPlanList,
  returnVistList,
  addVistList
} from "@/api/client";
class Search {
  customer_name_or_phone = "";
  start_time = "";
  end_time = "";
}
class Detail {
  customer_id = "";
  repair_plan_content = "";
}
class Rules {
  customer_id = [
    { required: true, message: "请输入客户名称", trigger: "change" }
  ];
  repair_plan_content = [
    { required: true, message: "请选择方案内容", trigger: "blur" }
  ];
}
class Options {
  customer_id = [];
}
class Page {
  total = 0;
  page = 1;
  limit = 10;
}
export default {
  name: "ClientList",
  components: {
    pagination
  },
  props: {
    clienId: {
      type: String,
      default: ""
    },
    consignee: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      page: new Page(),
      search: new Search(),
      options: new Options(),
      detail: new Detail(),
      rules: new Rules(),
      list: [],
      idList: "",
      visitClient: false,
      notHave: false
    };
  },
  filters: {
    statusFilter(val) {
      return ["启用", "禁用"][+val];
    }
  },
  computed: {
    ...mapGetters(["userInfo"])
  },
  mounted() {
    this.detail.customer_id = this.clienId ? this.clienId : "";
    this.getList();
  },
  methods: {
    // 获取选项
    getOptions() {
      clientList({ page: 1, limit: 1000000 }).then(res => {
        this.options.customer_id = res.list;
      });
      this.detail.customer_id = this.clienId;
    },
    getList(option) {
      if (option === "search") this.page = new Page();
      repairPlanList  ({
        ...this.page,
        ...this.search,
        customer_id: this.clienId
      }).then(res => {
        console.log(res);
        this.list = res.data.list;
        if (!this.list.length) {
          this.notHave = true;
        }
        this.page.total = res.data.dataCount;
      });
    },
    // 提交
    submitForm(formName) {
      // this.checking();
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.hint("添加该条修复方案", "add");
        } else {
          return false;
        }
      });
    },
    // 提示
    hint(text, type) {
      this.$confirm(`${text},是否确定？`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          if (type == "add") {
            this.confirm(type);
          } else {
            this.getExport();
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 导出
    getExport() {
      vistExport({ id: this.idList, type: 1 }).then(res => {
        window.open(res.data.url);
      });
    },
    // 确认提交
    confirm(type) {
      addPlanList({ ...this.detail }).then(res => {
        this.$message({
          type: "success",
          message: res.msg
        });
        this.visitClient = false;
        this.getList();
      });
    },
    // 改变表格选中状态
    handleSelectionChange(val) {
      this.idList = val.map(i => {
        return i.id;
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.mainColor {
  color: #2dc0a3;
}
.content {
  height: calc(100% - 56px);
  overflow-y: auto;
}
.bgW {
  background: #fff;
  border-radius: 3px;
  padding: 10px;
  margin-bottom: 20px;
}

.el-form-item {
  margin: 0px 20px 3px 0;
}
.accountCon {
  background: #fff;
  padding: 0px 10px 30px;
  .btnBox {
    display: flex;
    justify-content: space-between;
  }
  .entryBox {
    height: 600px;
    overflow-y: scroll;
    .entryRow1 {
      display: flex;
      .item-circle {
        width: 18px;
        height: 18px;
        z-index: 2;
        border-radius: 9px;
        background-color: white;
        border: 5px solid #a5ecd7;
      }
      .clientName {
        line-height: 30px;
        font-size: 16px;
        font-weight: bold;
      }
    }
    .entryRow2 {
      color: #999;
      margin: 10px 0 0 20px;
      display: flex;
      font-size: 14px;
    }
    .entryRow3 {
      color: #444;
      margin: 10px 0 20px;
      font-size: 15px;
    }
  }
  ::-webkit-scrollbar {
    display: none;
  }
}
.frame {
  .el-form-item {
    margin: 0px 20px 26px 0;
  }
}
.footerBtn {
  text-align: right;
}
</style>
